﻿using System.Collections.ObjectModel;

using Xc.DataAccess.CodeReader;
using Xc.DataAccess.Core;
using System;
using System.Linq;

namespace Xc.Logics.CodeReaders.ViewModels
{
    public class MainViewModel : ViewModelBase
    {
        private ObservableCollection<FilterLayer> filters = new ObservableCollection<FilterLayer>();
        private FilterDetailInfo[] filerSources;
        private FilterLayer selectFilter;
        private string filterText;
        private bool isRunning = false;
        private int[] cameraIndex = new int[] { 0, 1 };
        private int index;
        /// <summary>
        /// 相机序号
        /// </summary>
        public int Index
        {
            get => index; set
            {
                index = value;
            }
        }
        public int[] CameraIndex
        {
            get => cameraIndex; set
            {
                cameraIndex = value;
                RaisedPropertyChanged();
            }
        }        /// <summary>
                 /// 过滤器列表
                 /// </summary>
        public ObservableCollection<FilterLayer> Filters
        {
            get => filters; set
            {
                filters = value;
                RaisedPropertyChanged();
            }
        }
        /// <summary>
        /// 过滤器源
        /// </summary>
        public FilterDetailInfo[] FilerSources
        {
            get
            {
                if (filerSources == null)
                {
                    return null;
                }
                if (!string.IsNullOrEmpty(FilterText))
                {
                    return filerSources.Where(p => p.ProcessName.Contains(FilterText)).ToArray();
                }
                return filerSources;
            }

            set
            {
                filerSources = value; RaisedPropertyChanged();

            }
        }
        public bool IsRunning
        {
            get => isRunning; set
            {
                isRunning = value;
                RaisedPropertyChanged();
            }
        }
        public string FilterText
        {
            get => filterText; set
            {
                filterText = value;
                RaisedPropertyChanged();
                RaisedPropertyChanged(nameof(filerSources));
            }
        }
        /// <summary>
        /// 选中的过滤器
        /// </summary>
        public FilterLayer SelectFilter
        {
            get => selectFilter; set
            {
                selectFilter = value;
                RaisedPropertyChanged();
            }
        }
    }
}
